package com.example.park

import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.lib_base.entity.CarTypeEntityItem
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class ParkViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {

    fun getCarType():Flow<PagingData<CarTypeEntityItem>> {
        return Pager(config = PagingConfig(pageSize = 10), pagingSourceFactory = {
            ParkSource(apiService)
        }).flow.cachedIn(viewModelScope)
    }
}